import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store";
import {
  baseInstance,
  instanceFacatory,
  baseGet,
  basePost,
} from "./apis/request.js";

// util 注册

import "@utils/tools.js";

// lib 注册
import "@libs/vant-plugins.js";

import "@assets/icons/iconfont.css";
import "@assets/styles/reset.css";
import "@assets/styles/gobal.scss";
//自定义插件注册
import "@components/plugins/index.js";

Vue.prototype.$basehttp = baseInstance; //网络请求
Vue.prototype.$baseGet = baseGet; //网络GET请求
Vue.prototype.$basePost = basePost; //网络POST请求
Vue.prototype.$httpFacatory = instanceFacatory; //网络请求工厂 可创建多请求实例
Vue.config.productionTip = false;

Vue.mixin({
  methods: {
    getAuthorized() {
      return "Bear " + localStorage.getItem("token");
    },
    onBrowserBack() {
      if (router.currentRoute.fullPath == "/") {
        window.history.pushState(null, null, router.currentRoute.fullPath);
        Vue.prototype.$toast({
          message: "已经是首页了",
        });
        
      }
    },
  },
  watch: {
    // $route(to, from) {
    //   console.log(router.currentRoute);
    // },
  },
  mounted() {
    window.addEventListener("popstate", this.onBrowserBack, false);
  },
  destroyed() {
    // 当页面销毁必须要移除这个事件，vue不刷新页面，不移除会重复执行这个事件
    window.removeEventListener("popstate", this.onBrowserBack, false);
  },
});

new Vue({
  router,
  store,
  render: (h) => h(App),
}).$mount("#app");
